package com.woniuxy02;

import java.util.*;

/**
 * @author 作者
 * @create 2025-06-06 14:23
 */
public class Test02 {
    public static void main(String[] args) {
        Collection<Student> list = new ArrayList();
        list.add(new Student(1,"zs",11));
        list.add(new Student(2,"ls",12));
        list.add(new Student(3,"ww",13));
//        list.add(new Student(4,"wxw",14));

        Iterator<Student> iterator = list.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next().name);
            System.out.println(iterator.next().age);
        }

    }

    private static void test05() {
        Collection<Integer> nums=new ArrayList<>();
        nums.add(1);
        nums.add(1);
        nums.add(1);
//        nums.add("aaaa");
        for(Integer num : nums){
            System.out.println(num);
        }
    }

    private static void test04() {
        Collection<String> list = new ArrayList<>();
        for(String str : list){
            System.out.println(str);
            System.out.println(str.concat("aaaa"));
        }
    }

    private static void test03() {
        Collection list = new ArrayList();
        list.add("a");
        list.add("b");
        list.add("c");
        //集合遍历1：转成数组，数组遍历
        Object[] array = list.toArray();
        //集合遍历2,增强for：for( 数据类型 变量 : 数组或者集合)
        for(Object obj : list){
            System.out.println(obj);
        }
        //集合遍历3,使用迭代器
        //获取当前集合的迭代器对象
        Iterator iterator = list.iterator();
        //判断是否存在下一个元素iterator.hasNext();
        //获取下一个元素iterator.next()
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }

    private static void test02() {
        Collection list1 = new ArrayList();
        System.out.println(list1.isEmpty());
        System.out.println(list1.size());
    }

    private static void test01() {
        Collection list1 = new ArrayList();
        list1.add("a");
        list1.add("b");
        list1.add("c");
        Collection list2 = new ArrayList();
        list2.add("a");
        list2.add("b");

        System.out.println(list1.containsAll(list2));
        System.out.println(list2.containsAll(list1));
    }
}
